function validarCPF(temp) {
  var temp = document.getElementById("cpf").value;
  var cpf = temp.substr(0,3) + temp.substr(4,3) + temp.substr(8,3) + temp.substr(12,2);
  var soma = (cpf[0]*10+cpf[1]*9+cpf[2]*8+cpf[3]*7+cpf[4]*6+cpf[5]*5+cpf[6]*4+cpf[7]*3+cpf[8]*2) % 11;
  var dv1 = (soma < 2) ? 0 : 11 - soma;
  soma = (cpf[0]*11+cpf[1]*10+cpf[2]*9+cpf[3]*8+cpf[4]*7+cpf[5]*6+cpf[6]*5+cpf[7]*4+cpf[8]*3+cpf[9]*2) % 11;
  var dv2 = (soma < 2) ? 0 : 11 - soma;
  var resposta = document.getElementById("resposta");
  
  

  if(dv1 != cpf[9] || dv2 != cpf[10]) {
    resposta.firstChild.nodeValue = "CPF inv�lido!";
    resposta.style.color = "red";
  }
  else {
    resposta.firstChild.nodeValue = "CPF v�lido!";
    resposta.style.color = "blue";
  }
  
  return false;
}



function valida()
			{
				var n = document.getElementById("nome");
				var e = document.getElementById("email");
				var sex_mas = document.getElementById("masc");
				var sex_fem = document.getElementById("fem");
				var cpf = document.getElementById("cpf");
				var qtspan = document.getElementsByTagName('span').length;
				var resposta = new Array(qtspan);
				for(var i = 0; i < qtspan-1; i++) {
				resposta[i] =document.getElementsByTagName('span')[i];
				}
				
				var textnode=document.createTextNode("Campo Obrigatorio n�o preenchido");
				
				var el_span = document.createElement('strong');
			
				el_span.setAttribute('style', 'color: red');
				el_span.appendChild(textnode);

				if (n.value == "" || n.value.length < 3 )
				
				{   
										
					
					if(typeof (resposta[0].childNodes[1]) === 'undefined'){
					resposta[0].appendChild(el_span);

					}
					n.focus();
					return false;
				}else{
	
					resposta[0].removeChild(resposta[0].childNodes[1]);
					
				}
			
			if(cpf.value  == ""){
                                        if(typeof (resposta[2].childNodes[1]) === 'undefined'){
					resposta[2].appendChild(el_span);				
                                        cpf.focus();
                                        return false;
                                        }else{
                                           resposta[2].removeChild(resposta[2].childNodes[1]);

                                        }
				
			}
		
			
			//Validando Sexo
			if (!sex_mas.checked && !sex_fem.checked)
			{
			
				if(typeof (resposta[3].childNodes[1]) === 'undefined'){
					resposta[3].appendChild(el_span);				
                                        cpf.focus();
                                        return false;
                                        }else{
                                           resposta[3].removeChild(resposta[2].childNodes[1]);

                                        }
			}
			
			
				if (e.value  == "" || e.value.length < 5 || e.value.indexOf("@") == -1 || e.value.indexOf(".") == -1)	
			{
				
				if(typeof (resposta[5].childNodes[1]) === 'undefined'){
					resposta[5].appendChild(el_span);				
                                        cpf.focus();
                                        return false;
                                        }else{
                                           resposta[5].removeChild(resposta[2].childNodes[1]);

                                        }
				
				
			}
	
}



